from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon, QMovie  # 添加图标
from PyQt5 import QtCore
from PyQt5.QtCore import QCoreApplication
from ENT import Ui_MainWindow
from Seismic_Wave_Generator import SWG
from SWG import Ui_SWG
from SCG import Ui_Coe_Generator
from Coe_Generator import Coe_Generator


# import time


class MainWindow:
    """
    主界面类
    """

    def __init__(self):
        # UI_widget_Main.setMaximumSize(660, 500)
        # UI_widget_Main.setMinimumSize(660, 500)
        UI_widget_Main.setFixedSize(660, 500)
        # UI_widget_Main.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        UI_widget_Main.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint)

        Entrance_UI.quit.clicked.connect(self.quit_program)
        Entrance_UI.pushButton_do_SWG.clicked.connect(self.do_SWG)
        Entrance_UI.pushButton_do_SCG.clicked.connect(self.do_SCG)

        Entrance_UI.pushButton_do_SCG.setStyleSheet("QPushButton{font: 20pt '宋体'}"
                                                    "QPushButton{color:black}"
                                                    "QPushButton:hover{color:blue}"
                                                    "QPushButton{background-color:rgb(230,255,255)}"  # 203,98,255
                                                    "QPushButton{border:2px}"
                                                    "QPushButton{border-radius:10px}"
                                                    "QPushButton{padding:2px 4px}")
        Entrance_UI.pushButton_do_SWG.setStyleSheet("QPushButton{font: 20pt '宋体'}"
                                                    "QPushButton{color:black}"
                                                    "QPushButton:hover{color:blue}"
                                                    "QPushButton{background-color:rgb(170,255,255)}"
                                                    "QPushButton{border:2px}"
                                                    "QPushButton{border-radius:10px}"
                                                    "QPushButton{padding:2px 4px}")
        Entrance_UI.quit.setStyleSheet("QPushButton{font: 20pt '宋体'}"
                                       "QPushButton{color:black}"
                                       "QPushButton:hover{color:blue}"
                                       "QPushButton{background-color:rgb(0,255,255)}"
                                       "QPushButton{border:2px}"
                                       "QPushButton{border-radius:10px}"
                                       "QPushButton{padding:2px 4px}")
        Entrance_UI.background.setStyleSheet('QLabel{border:2px}'
                                             'QLabel{border-radius:10px}'
                                             'QLabel{padding:2px 4px}')
        Entrance_UI.xjtu_logo.setStyleSheet('QLabel{border-image:url(./source/picture/XJTU.jpg)}')
        Entrance_UI.pinggao_logo.setStyleSheet('QLabel{border-image:url(./source/picture/pinggao_logo.jpg)}')
        self.UI_widget_SCG = None
        self.COEUI = None
        self.stats_SCG = None
        self.UI_widget_SWG = None
        self.SWG_UI = None
        self.stats_SWG = None

        self.gif1 = QMovie('source/picture/shaking.gif')
        # self.set_transparent(Entrance_UI.background_2, 0.8)
        Entrance_UI.background.setMovie(self.gif1)
        self.gif1.start()

    @staticmethod
    def set_transparent(item, i):
        """
        设置部件透明度  0-1之间
        :param item:
        :param i:
        :return:
        """
        op = QtWidgets.QGraphicsOpacityEffect()
        op.setOpacity(i)
        item.setGraphicsEffect(op)

    def do_SCG(self):
        print("已进入地震影响系数曲线生成模块！")
        self.UI_widget_SCG = QtWidgets.QWidget()  # UI 的显示部件
        # 整个widget仅起到界面承载作用，部件都在类上，但是进度条等要以widget为父类
        self.COEUI = Ui_Coe_Generator()
        self.COEUI.setupUi(self.UI_widget_SCG)
        self.stats_SCG = Coe_Generator(self.UI_widget_SCG, self.COEUI, UI_widget_Main)  # 主程序类
        self.UI_widget_SCG.show()  # 显示地震影响系数曲线生成主界面
        UI_widget_Main.setVisible(False)

    def do_SWG(self):
        print("已进入地震波时程曲线生成模块！")
        self.UI_widget_SWG = QtWidgets.QWidget()  # UI 的显示部件
        # 整个widget仅起到界面承载作用，部件都在类上，但是进度条等要以widget为父类
        self.SWG_UI = Ui_SWG()
        self.SWG_UI.setupUi(self.UI_widget_SWG)
        self.stats_SWG = SWG(self.UI_widget_SWG, self.SWG_UI, UI_widget_Main)  # 主程序类
        self.UI_widget_SWG.show()  # 显示地震波生成主界面
        UI_widget_Main.setVisible(False)

    @staticmethod
    def quit_program():
        print("已退出程序，欢迎下次使用！")
        QCoreApplication.quit()


"=============程序开始执行===================="
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)  # 自适应分辨率

app = QApplication([])

"=============载入画面===================="
# splash = QSplashScreen(QtGui.QPixmap('./GUI/picture/loading.jpg'))
# splash.showMessage("加载中，请稍候......", QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
# splash.setFont(QFont("Roman times", 18, QFont.Bold))
# splash.show()  # 显示启动界面
# # qApp.processEvents()  # 处理主进程事件
# time.sleep(1)
"=============设置图标===================="
app.setWindowIcon(QIcon('source/picture/logo.ico'))

"=============建立UI================="
# Qt Designer默认继承的object类，不提供show()显示方法，
# 所以我们生成一个QWidget对象来重载我们设计的SWG_UI类，达到显示效果。
UI_widget_Main = QtWidgets.QWidget()  # UI 的显示部件
# 整个widget仅起到界面承载作用，部件都在类上，但是进度条等要以widget为父类
Entrance_UI = Ui_MainWindow()
Entrance_UI.setupUi(UI_widget_Main)
stats_main = MainWindow()  # 主程序类
# splash.close()  # 隐藏启动界面
UI_widget_Main.show()  # 显示地震波生成主界面
print("进入程序，欢迎使用！")
app.exec_()
